package dreamtime.dreamnews;

public class ToHtml {
	 /**
	 * @param str
	 * @return
	 */
	public static String convert(String str)
	    {
	        if(str==null)
	            return "";
	        StringBuffer sb = new StringBuffer();
	        char c;
	        int len = str.length();
	        for (int i = 0; i < len; i++)
	        {
	            c = str.charAt(i);
	            switch(c)
	            {
	            case ' ':
	                sb.append("&nbsp;");
	               break;
	            case '\n':
	                sb.append("<br>");
	               break;
	            case '\r':
	               break;
	            case '\'':
	                sb.append("&#39;");
	                break;
	            case '<':
	                sb.append("&lt;");
	                break;
	            case '>':
	                sb.append("&gt;");
	                break;
	            case '&':
	                sb.append("&amp;");
	                break;
	            case '"':
	                sb.append("&#34;");
	                break;
	            case '\\':
	                sb.append("&#92;");
	                break;
	            default:
	                sb.append(c);
	            }
	        }
	        return sb.toString();
	    }   
}
